package com.kaiwukj.android.ufamily.mvp.ui.activity;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseActivity;
import com.kaiwukj.android.ufamily.mvp.ui.widget.RecycleJZVideoPlayer;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jzvd.JZDataSource;
import cn.jzvd.JzvdStd;

import static com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt.VideoPlay;

/**
 * 单个视频
 *
 * @author Charles
 * @date 2019/8/19.
 * description：Kaiwu
 */
@Route(path = VideoPlay)
public class VideoActivity extends BaseActivity {
    @BindView(R.id.video_player)
    RecycleJZVideoPlayer videoPlayer;

    @Autowired
    String videoUrl;
    @Autowired
    String coverUrl;
    @Autowired
    String title;

    @OnClick(R.id.container_left)
    void onBackClick() {
        onBackPressedSupport();
    }

    @Override
    protected int getLayoutId() {
        ARouter.getInstance().inject(this);
        return R.layout.pop_video_player_fix;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        JZDataSource dataSource = new JZDataSource(videoUrl);
        videoPlayer.setUp(dataSource, JzvdStd.SCREEN_NORMAL);
        Glide.with(this).load(coverUrl).into(videoPlayer.posterImageView);
        videoPlayer.startVideo();
        videoPlayer.titleTextView.setText(title);

        /*videoPlayer.setPlayerType(NiceVideoPlayer.TYPE_IJK);
        TxVideoPlayerController controller = new TxVideoPlayerController(this);
        controller.setTitle(title);
        Glide.with(this).load(coverUrl).into(controller.imageView());
        videoPlayer.setController(controller);
        videoPlayer.setUp(videoUrl, null);*/

//        Glide.with(this).load(coverUrl).into(videoPlayer.ivThumb);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        JzvdStd.releaseAllVideos();
    }
}
